package com.example.controller;

import com.example.entity.User;
import com.example.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * Author:sun
 * Date:2021/12/19
 * Note:*
 **/
@Controller
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserService userService;

    //网页测试可以输入如下，然后在数据库里面看。成功后页面将会返回json数据；
    //http://localhost:8080/user/register?userName=testusername&userPassword=testpassword&userRealName=lilei&userImage=03.jpg
    @RequestMapping("/register")
    //通过json格式返回对象；
    @ResponseBody
    public User register(User user) {
        return userService.userRegister(user);
    }

    //网页测试输入如下，成功返回index.jsp页面；
    //http://localhost:9999/demo1/user/register1?userName=Luiiicy&userPassword=564333&userRealName=LuLei&userImage=03.jpg
    @RequestMapping("/register1")
    public String register1(User user) {
        userService.userRegister(user);
        //没有配置视图解析器是return "/index.jsp"；application.yml配置了视图解析器后
        return "index";
    }

    @RequestMapping("/test")
    @ResponseBody
    public String rTest() {
        return "rTest";
    }
}
